package com.itheima.publisher;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class SpringAMQPtest {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Test
    void testSimpleQueue(){
        //队列名称
        String queueName ="simple.queue";
        //消息名称
        String msg ="hello amqp!";

        rabbitTemplate.convertAndSend(queueName,msg);
    }

    @Test
    void testWorkQueue() throws InterruptedException {
        //队列名称
        String queueName ="work.queue";
        for (int i = 0; i < 50; i++) {

            //消息名称
            String msg ="hello worker,message_" + i;

            rabbitTemplate.convertAndSend(queueName,msg);

            Thread.sleep(20);
        }
    }

    @Test
    void testSendFanout(){
            //交换机名称
            String exchangeName ="pengge.fanout";
            //消息名称
            String msg ="hello, everyone!";

            rabbitTemplate.convertAndSend(exchangeName,"",msg);
        }


    @Test
    void testSendDirect(){
        //交换机名称
        String exchangeName ="pengge.direct";
        //消息名称
        String msg ="红色警报， 由于日本排放核污水， 惊现哥斯拉!";

        rabbitTemplate.convertAndSend(exchangeName,"yellow",msg);
    }

    @Test
    void testSendTopic(){
        //交换机名称
        String exchangeName ="pengge.topic";
        //消息名称
//        String msg ="红色警报， 由于日本排放核污水， 惊现哥斯拉!";
        String msg ="今天天气不错 ，我心情挺好的 !";

//        rabbitTemplate.convertAndSend(exchangeName,"japan.news",msg);
//        rabbitTemplate.convertAndSend(exchangeName,"china.news",msg);
        rabbitTemplate.convertAndSend(exchangeName,"china.weather",msg);
    }


}
